package getsmart.project.activity;

import getsmart.project.R;
import getsmart.project.database.DBStudyType;

import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;

public class ListBelajar extends Activity implements View.OnClickListener{
	public int tempID = 1;
	public int getSize;
	String [] arrData;
	Button [] profName;
	DBStudyType dbPelajaran;
	EditText pertanyaan, kategori;
	TableLayout tabel4data;// tabel for data
	public static String typeStudy= "";
	private static void getTypeStudy(String namaPelajaran){
		ListBelajar.typeStudy = namaPelajaran;
	}
	public static int idBacaan = 0;
	private static void getIdStudy(int hasil){
		ListBelajar.idBacaan = hasil;
	}
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_belajar);
		 
		dbPelajaran = new DBStudyType(this);
		tabel4data = (TableLayout) findViewById(R.id.table_data_pelajaran);
		viewData();
	}
	protected void viewData() {
		// TODO Auto-generated method stub
		while (tabel4data.getChildCount() > 1) {
			tabel4data.removeViewAt(1);
		}
 
		ArrayList<ArrayList<Object>> data = dbPelajaran.getProfile(ChooseKelas.kelasSiswa);//
		
		arrData = new String[data.size()];

		for (int posisi = 0; posisi < data.size(); posisi++) {
			TableRow tabelBaris = new TableRow(this);
			ArrayList<Object> baris = data.get(posisi);
			getSize = data.size();
			arrData = new String[data.size()];
			Button[] profName = new Button[data.size()]; 
			tempID = Integer.parseInt(baris.get(0).toString());
			profName[posisi] = new Button(this);
			profName[posisi].setBackgroundResource(R.drawable.button_lainjuga);
			profName[posisi].setText(baris.get(2).toString());
			arrData[posisi] = baris.get(1).toString();
			profName[posisi].setOnClickListener(this);
			profName[posisi].setId(posisi);
			tabelBaris.addView(profName[posisi]);		
			tabel4data.addView(tabelBaris);
			tempID++;
		}
	}
	@Override
	public void onClick(View v){
		
		Button b = (Button)v;
		for(int i = 0; i<getSize;i++){
			if(b.getId() == i){
				idBacaan = i;
				typeStudy = b.getText().toString();
				if(ChooseMenu.MenuPilihan == "Belajar"){
					Intent in = new Intent(ListBelajar.this,ChooseBelajar.class);
					startActivity(in);
				}
				if(ChooseMenu.MenuPilihan == "Test"){
					Intent in = new Intent(ListBelajar.this,ListBab.class);
					startActivity(in);
				}
				if(ChooseMenu.MenuPilihan == "Statistik"){
					Intent in = new Intent(ListBelajar.this,ListBab.class);
					startActivity(in);
				}
			}
		}
	}
}
